import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ManagerApi } from '#/api/pilot/manager';

import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: '飞手姓名',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入飞手姓名',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'idNumber',
      label: '身份证',
      component: 'Input',
      componentProps: {
        placeholder: '请输入身份证',
      },
    },
    {
      fieldName: 'certNumber',
      label: '证书编号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入证书编号',
      },
    },
    {
      fieldName: 'certCreated',
      label: '证书创建时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'certExp',
      label: '证书过期时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'certAuthority',
      label: '发证机构',
      component: 'Input',
      componentProps: {
        placeholder: '请输入发证机构',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: '飞手姓名',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入飞手姓名',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'idNumber',
      label: '身份证',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入身份证',
      },
    },
    {
      fieldName: 'certNumber',
      label: '证书编号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入证书编号',
      },
    },
    // {
    //   fieldName: 'certCreated',
    //   label: '证书创建时间',
    //   component: 'RangePicker',
    //   componentProps: {
    //     ...getRangePickerDefaultProps(),
    //     allowClear: true,
    //   },
    // },
    // {
    //   fieldName: 'certExp',
    //   label: '证书过期时间',
    //   component: 'RangePicker',
    //   componentProps: {
    //     ...getRangePickerDefaultProps(),
    //     allowClear: true,
    //   },
    // },
    // {
    //   fieldName: 'certAuthority',
    //   label: '发证机构',
    //   component: 'Input',
    //   componentProps: {
    //     allowClear: true,
    //     placeholder: '请输入发证机构',
    //   },
    // },
    // {
    //   fieldName: 'createTime',
    //   label: '创建时间',
    //   component: 'RangePicker',
    //   componentProps: {
    //     ...getRangePickerDefaultProps(),
    //     allowClear: true,
    //   },
    // },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<ManagerApi.Manager>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    // {
    //   field: 'id',
    //   title: '编号',
    //   minWidth: 120,
    // },
    {
      field: 'name',
      title: '飞手姓名',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      field: 'idNumber',
      title: '身份证',
      minWidth: 120,
    },
    {
      field: 'certNumber',
      title: '证书编号',
      minWidth: 120,
    },
    {
      field: 'certCreated',
      title: '证书创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'certExp',
      title: '证书过期时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'certAuthority',
      title: '发证机构',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
